package com.cn.controller;

import org.flowable.engine.*;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 学生审批测试
 */
@RestController
@RequestMapping("/student")
public class FlowableController {

    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private TaskService taskService;

    @Autowired
    private RepositoryService repositoryService;

    @Autowired
    private IdentityService identityService;


    /**
     * 1.学生写清楚条件进行审批的方式
     */
    @PostMapping("/studentExamine")
    public Object studentExamine(){
        Map<String,Object> map = new HashMap<>();
        map.put("stu","李老师");
        map.put("stu01","王老师");
        map.put("stu02","情网老师");
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("学生管理系统01",map);
        return "成功";
    }

    /**
     * 根据名称查询代表那任务
     * @param name
     * @return
     */
    @GetMapping("/studentList")
    public String studentList(String name){
        List<Task> list = taskService.createTaskQuery()
                .taskAssignee(name)
                .list();
        Map<String, Object> map = null;
        for (Task task : list) {
            map = taskService.getVariables(task.getId());
        }

        return list+"-"+map;
    }

    @GetMapping("/examineComplete")
    public String examineComplete(String id){
        Map<String,Object> map = new HashMap<>();
        map.put("stu","李老师");
        map.put("stu01","王老师");
        map.put("stu02","情网老师");
        taskService.complete(id,map);
        return "成功";
    }


}
